// 导入路由
// import { BrowserRouter as Router, Route, Switch, Redirect } from "react-router-dom"
import { Router, Route, Switch, Redirect } from "react-router-dom"
import { customHistory } from '@/utils'
// 项目页面
import { Login } from './pages/Login/Login.js'
import { GeekLayout } from './pages/GeekLayout/GeekLayout.js'
import { NotFound } from './pages/NotFound/NotFound.js'
// 跟组件样式
import './App.scss'
import { isAuth } from "./utils/token.js"

const App = () => {
  return (
    <Router history={customHistory}>
      <div className="app">
        <Switch>
          {/* 路由重定向 */}
          <Route exact path={'/'} render={() => <Redirect to={'/home'}></Redirect>}></Route>
          {/* <Route path={'/home'} component={GeekLayout}></Route> */}
          {/* 鉴权优化 */}
          <Route path={'/home'} render={(props) => {
            console.log('home 组件的 props=>', props);
            if (isAuth()) {
              return <GeekLayout></GeekLayout>
            }
            return (
              <Redirect to={{
                pathname: '/login',
                state: {
                  from: props.location.pathname
                }
              }}></Redirect>
            )
          }}></Route>
          <Route path={'/login'} component={Login}></Route>
          <Route component={NotFound}></Route>
        </Switch>
      </div>
    </Router>
  )
}

export default App